package com.zxk.blog.controller;

import com.zxk.api.dto.FundAnalysiseDto;
import com.zxk.api.service.FundAnalysiseService;
import com.zxk.api.service.FundService;
import com.zxk.core.common.model.Fund;
import com.zxk.core.common.model.FundAnalysise;
import com.zxk.core.common.util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Api("爬虫对外接口")
@RestController
@RequestMapping("/blog/api/fund/analysise")
public class FundController {

    @ApiOperation(value="基金分析页面",notes="基金分析页面")
    @PostMapping("/fund-analysise-page")
    public JsonData page(String fundCode){
        return new JsonData().buildSuccess(fundCode,200);
    }

    @Autowired
    private FundAnalysiseService fundAnalysiseService;

    @Autowired
    private FundService fundService;


    @ApiOperation(value="基金分析ajax",notes="基金分析ajax")
    @PostMapping(value = "/all-funds")
    public JsonData allFunds(FundAnalysise fundAnalysise){
        List<FundAnalysise> fundAnalysises = fundAnalysiseService.find(fundAnalysise);
        return JsonData.buildSuccess(fundAnalysises,200);
    }

    @ApiOperation(value="基金列表",notes="基金列表")
    @PostMapping("/fund-list")
    public JsonData fundList(){
        List<Fund> fundList = fundService.findAll();
        return JsonData.buildSuccess(fundList,200);
    }

//    @RequestMapping("/add-fund")
//    public String addFund(Fund fund){
//        this.fundService.save(fund);
//        return "redirect:/fund/analysise/fund-list";
//    }

    @PostMapping("/fund-order-by-time")
    public JsonData fundsOrderByTime(){
        List<Fund> funds = this.fundService.selectOrderFundByCreateTime();
        return JsonData.buildSuccess(funds,200);
    }

    @PostMapping("/fund-analysis-time")
    public JsonData fundsByTimeCode(FundAnalysise fundAnalysise){
        List<FundAnalysiseDto> fundAnalysiseDtos = this.fundAnalysiseService.findByTimeBlur(fundAnalysise);
        JsonData jsonData = new JsonData(200,fundAnalysiseDtos,"查询成功");
        return jsonData;
    }
}
